package com.woshua.gsonmodel

import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import java.lang.NumberFormatException
import java.lang.reflect.Type

/**
 * @author Steven.zhao
 * email:hongtu.zhao@goodwinsoft.net
 * date:2019/7/23
 * desc:
 */
class IntDefaultAdapter:JsonDeserializer<Int> {
    override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): Int {
        if(json?.asString=="")
        {
            return 0
        }
        try {
            return json!!.asInt
        }catch (e:NumberFormatException)
        {
            return 0
        }
    }
}